package com.hospital.doctor.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hospital.doctor.pojo.Drug;
import com.hospital.doctor.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/drug")
@CrossOrigin
public class DrugController {

    @Autowired
    private DrugService drugService;

    @RequestMapping("/selectAll/{page}/{size}")
    public Map<String,Object> selectAll(@PathVariable("page")int page, @PathVariable("size")int size){
        PageHelper.startPage(page,size);
        PageInfo<Drug> drugPageInfo = new PageInfo<>(drugService.selectAll());
        Map<String,Object> map = new HashMap<>();
        map.put("msg",drugPageInfo);
        return map;
    }

    @RequestMapping("/selectByDrName/{drName}")
    public List<Drug> selectByDrName(@PathVariable("drName") String drName){
        return drugService.selectByDrName(drName);
    }

}
